<script>
    nmenuindex=3;
</script>
<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
        include ('controller/JO_4rumController.php');
        $JO["forum"]= JO( array( "EN" => "Forum","VI"=>"Diễn Đàn") );
        $JO["topic"]= JO( array( "EN" => "Topics","VI"=>"Chủ Đề") );
        $JO["lastpost"]= JO( array( "EN" => "Last Posts","VI"=>"Bài Gửi Mới Nhất") );
        $JO["postnum"]= JO( array( "EN" => "Posts","VI"=>"Bài Viết") );
        $JO["commentnum"]= JO( array( "EN" => "Comment","VI"=>"Nhận Xét") );
        $JO["post"]= JO( array( "EN" => "Posts","VI"=>"Bài Viết") );
        $JO["lastcomment"]= JO( array( "EN" => "Last Comment","VI"=>"Nhận Xét Mới Nhất") );
        $JO["postby"]= JO( array( "EN" => "Post by","VI"=>"Đăng bởi") );
        $JO["postdate"]= JO( array( "EN" => "Post Date","VI"=>"Ngày Đăng") );
        $JO["postnew"]= JO( array( "EN" => "+Add New Post","VI"=>"+Viết Bài Mới") );
        $JO["commentat"]= JO( array( "EN" => "Comment At","VI"=>"Nhận xét lúc") );
        $JO["addedpost"]= JO( array( "EN" => "sussess","VI"=>"Đăng bài viết thành công, bài viết của bạn cần được kiểm duyệt và sẽ được chấp nhận. cảm ơn bạn đã tham gia viết bài") );
        $JO["title"]= JO( array( "EN" => "Title","VI"=>"Tiêu Đề") );
        $JO["briefcontent"]= JO( array( "EN" => "Briefcontent","VI"=>"Mô Tả Ngắn Gọn") );
        $JO["content"]= JO( array( "EN" => "Content","VI"=>"Nội Dung") );
        $JO["imgcode"]= JO( array( "EN" => "Image Code","VI"=>"Mã Xác Nhận") );
        $JO["preview"]= JO( array( "EN" => "Preview","VI"=>"Xem Trước") );
        $JO["closepreview"]= JO( array( "EN" => "Close Preview","VI"=>"Bỏ Xem Trước") );
        $JO["add"]= JO( array( "EN" => "OK","VI"=>"Đăng Bài") );
        $JO["login"]= JO( array( "EN" => "Please,login...","VI"=>"Bạn Cần Phải Đăng Nhập.") );
        $JO["noscript"]= JO( array( "EN" => "Don't use SCRIPT","VI"=>"Không được sử dụng mã SCRIPT.") );
?>


<div style="
             width: 960px;background: url(JO_images/hr.gif1) repeat-x top left #222;
             position: relative;float:left;

             ">
              <? include 'JO_007_nav1.php';?>

            <div class="mar8i"></div>
            <div style="
                 margin-left: 0px;
                 " class="bar_720i">
                <div class="JO_h1i"><?=$JO["postnew"]?></div>
                <span id="JO_addedi">
                <?
                if(isset($_SESSION[ "JO_account_id" 		])){
                    $topic=isset($_REQUEST["topic"])?$_REQUEST["topic"]:"";


                    ?>
                <form id="frm" name="frm"
                      onsubmit="return false;"
                      action="" method="post"
                      target="JO_integration_asynchronous"
                      >
                    <input type="hidden" id="JO_controller" name="JO_controller" value="JO_4rumController"/>
                    <input type="hidden" id="JO_action" name="JO_action" value="addnewpost"/>
                <table class="tbi" style="width: 704px;margin: 4px 0 0 8px">
                    <tr>
                        <th style="width:100px;"><?=$JO["topic"]?></th>
                        <td>
                            <select
                                id="cbxchude"
                                name="cbxchude"
                                class="input_selecti" style="width: 574px;">
                                <?
                                $datatopic=forumModule::getTopicsOfComment();
                                if($datatopic==null){
                                    echo "<option value=''>Data is empty</option>";
                                }else{
                                    foreach ($datatopic as $rowtopic){
                                       ?>
                                <option <?=($topic==(isset($rowtopic["subject"])?$rowtopic["subject"]:"")?"selected=1":"")?> value="<?=isset($rowtopic["key"])?$rowtopic["key"]:""?>"><?=isset($rowtopic["subject"])?$rowtopic["subject"]:""?></option>
                                        <?
                                    }
                                }
                                ?>
                                
                            </select>
                            
                        </td>
                    </tr>
                    <tr>
                        <th><?=$JO["title"]?></th>
                        <td>
                            <input
                                id="txttieude" name="txttieude"
                                class="input_texti" type="text" style="width: 556px;"/>
                        </td>
                    </tr>
                    <tr>
                        <th><?=$JO["briefcontent"]?></th>
                        <td>
                            <textarea
                                id="txtnoidungnho" name="txtnoidungnho" rows="2"
                                class="input_texti" style="width: 556px;height: 32px;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th><?=$JO["content"]?></th>
                        <td>
                            
                        </td>
                    </tr>
                </table>
                <style type="text/css">
                    #JO_text_editori * {
                        color: #111;
                    }
                </style>
                <div id="JO_text_editori" style=";width: 686px;margin-left: 8px;">
                    <textarea
                        id="txtnoidunglon" name="txtnoidunglon"
                        class="input_texti" rows="20" style="width:582px;height:336px;"></textarea>
                </div>
                <table class="tbi" style="width: 704px;margin: 4px 0 0 8px">
<!--                    <tr>
                        <td colspan="2">
                            <textarea
                                            id="txtnoidunglon" name="txtnoidunglon"
                                            class="input_texti" rows="20" style="width: 672px;height:336px; "></textarea>
                        </td>
                    </tr>-->
                    <tr>
                        <th><?=$JO["imgcode"]?></th>
                        <td>
                            <input id="txtmaxacnhan" name="txtmaxacnhan"
                                class="input_texti" type="text" style="width: 100px;"/>
                            <div style="width: 100px; float: left; height: 26px">
                                <img alt="" id="siimage"  align="left" style="padding: 4px; border: 0px;width: 48px;height: 26px;" src="captcha/create_image.php" />
                                <a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = 'captcha/create_image.php'; return false">
                                    <img id="refresh_capcha" name="refresh_capcha" style="width: 26px; float: left; height: 26px;padding-top: 4px;"  src="php_captcha/images/refresh7.png" alt="Reload Image" border="0" onclick="this.blur()" align="bottom" />
                                </a>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td id="JO_errormsg" colspan="2">
                            <?=$JO["noscript"]?>
                        </td>
                    </tr>
                </table>
                <table class="tbi" style="width: 704px;margin: 0 0 4px 8px">
                    <tr>
                        <th>
                            <input 
                                type="button"
                                id="btndangbai" name="btndangbai"
                                class="input_buttoni" value="<?=$JO["add"]?>"/>

                            <input
                                id="btnxemtruoc" name="btnxemtruoc"
                                type="button" class="input_buttoni" value="<?=$JO["preview"]?>" style="margin-left: 8px;"/>
                            <input
                                id="btntatxemtruoc" name="btntatxemtruoc"
                                type="button" class="input_buttoni" value="<?=$JO["closepreview"]?>" style="margin-left: 8px;"/>
                        </th>
                        
                    </tr>
                    <tr>
                        <td>Nội Dung Bài Viết Sẽ Hiện Thị giống như vậy</td>
                    </tr>
                </table>
                </form>
                <div id="JO_viewbeforepost" style="width: 704px;margin:8px 0 8px 8px;">
                    
                </div>
                    <?
                }else{
                ?>

                <div style="float: left;margin-bottom: 8px; width: 700px;">
                    <?=$JO["login"]?>
                </div>
                <?
                }
                ?>
                </span>
            </div>
</div>
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
        // General options
        width:"704",
        plugin_preview_width : "720",
        plugin_preview_height : "500",
        mode : "exact",
        elements : "txtnoidunglon",
        theme : "advanced",
        plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "code,fullscreen,preview,help,|,undo,redo,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,image,|,forecolor,backcolor,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking",
        theme_advanced_buttons3 : "styleprops,spellchecker,tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,ltr,rtl",
        
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Skin options
        skin : "o2k7",
        skin_variant : "black",

        // Example content CSS (should be your site CSS)
        content_css : "css/example.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "js/template_list.js",
        external_link_list_url : "js/link_list.js",
        external_image_list_url : "js/image_list.js",
        media_external_list_url : "js/media_list.js",

        // Replace values for the template plugin
        template_replace_values : {
                username : "Some User",
                staffid : "991234"
        }
});
</script>
<script>
    function _utf8_encode(string){
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

                var c = string.charCodeAt(n);

                if (c < 128) {
                        utftext += String.fromCharCode(c);
                }
                else if((c > 127) && (c < 2048)) {
                        utftext += String.fromCharCode((c >> 6) | 192);
                        utftext += String.fromCharCode((c & 63) | 128);
                }
                else {
                        utftext += String.fromCharCode((c >> 12) | 224);
                        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                        utftext += String.fromCharCode((c & 63) | 128);
                }

        }

        return utftext;
    }
    function getText(){
	var content = "", body = tinyMCE.activeEditor.getDoc().body;

	if(body.textContent) content = body.textContent; // Mozilla (Gecko)
	if(body.innerText) content = body.innerText; // Internet Explorer
	if(content == "") content = tinyMCE.activeEditor.getContent(); // other browsers

	//content = content.replace(/<\/?[^>]+>/g, "");
	content=tinyMCE.get("txtnoidunglon").getContent();
        //alert(content);
        return content;
    }
    //var text = getText();
    $("#btntatxemtruoc").click(
        function (){
           $("#JO_viewbeforepost").html("");
        }
    );
    $("#btnxemtruoc").click(
        function (){
           $("#JO_viewbeforepost").html(getText());
        }
    );
    $("#btndangbai").click(
        function (){
            var surl="controller/JO_ajax_navigation.php";
            var sdata="JO_controller=JO_4rumController&JO_action=addnewpost";
            sdata+="&cbxchude="+$("#cbxchude").val();
            sdata+="&txttieude="+escape(_utf8_encode($("#txttieude").val()));
            sdata+="&txtnoidungnho="+escape(_utf8_encode($("#txtnoidungnho").val()));
            sdata+="&txtnoidunglon="+escape(_utf8_encode(getText()));
            sdata+="&txtmaxacnhan="+$("#txtmaxacnhan").val();
            //$("#JO_errormsg").html(surl+"?"+sdata);
            jQuery.ajax({
                type:"POST", //Phương thức gửi request là POST hoặc GET
                data:sdata, //tham số gửi kèm
                dataType:"text", //kiểu dữ liệu trả về, mặc định là text
                url:surl, //Đường dẫn tới nơi xử lý request ajax
                success: function (data){ //hàm gọi về khi thực hiện thành công
                    // mã lệnh
                    try {
                        
                        var getData = $.parseJSON(data);
                        if(getData.nresult<0){
                            $("#JO_errormsg").html(getData.serrormsg);
                            switch(getData.nresult){
                                case -4:
                                    $("#txttieude").focus();
                                    break;
                                case -3:
                                    $("#txtnoidungnho").focus();
                                    break;
                                case -2:
                                    $("#txtnoidunglon").focus();
                                    break;
                                case -1:
                                    $("#txtmaxacnhan").focus();
                                    break;
                                case 0:
                                    
                                    break;
                            }
                            //$("#JO_errormsg").html( $("#JO_errormsg").html()+":"+data);
                        }else if(getData.nresult==0){
                            $("#JO_errormsg").html(getData.serrormsg);
                        }else if(getData.nresult==1){
                            $("#JO_addedi").html("<div style='padding:8px'><?=$JO["addedpost"]?></div>");
                        }
                        $("#siimage").attr("src","captcha/create_image.php");
                    } catch (exception) {
                        
                        $("#JO_errormsg").html('Có lỗi xảy ra. mà chả biết lỗi gì.<br/>----<br/>'+data);
                    }
                },
                error: function (){
                    alert('Có lỗi xảy ra');
               }
            });
        }
    );

</script>